
package com.kweative.network;

import com.kweative.format.Format;
import com.kweative.type.Node;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

/**
 *
 * @author henrik
 */
abstract public class Request {
    private HashMap<String,String> headers = new HashMap<String, String>();
    private String body = "";
    private Format format = null;
    private Node data = null;
    
    public String getBody() {
        return body;
    }

    public Node getData() {
        if (data == null && !body.isEmpty() && format != null) {
            data = format.parse(body);
        }
        return data;
    }

    protected void setData(Node data) {
        this.data = data;
    }

    public HashMap<String, String> headers() {
        return headers;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public Format getFormat() {
        return format;
    }

    public void setFormat(Format format) {
        this.format = format;
    }
    public void clear() {
        headers.clear();
        format = null;
        data = null;
        body = "";
    }

    abstract public void read(InputStream in) throws IOException;
}
